cmake_minimum_required(VERSION 3.9)
project(test)

message(STATUS "CMAKE_SOURCE_DIR--->${CMAKE_SOURCE_DIR}\nCMAKE_PROJECT_DIR---->${CMAKE_PROJECT_DIR}\nCMAKE_CURRENT_BINARY_DIR--->${CMAKE_CURRENT_BINARY_DIR}\nCMAKE_CURRENT_LIST_FILE--->${CMAKE_CURRENT_LIST_FILE}\nCMAKE_CURRENT_LIST_LINE---->${CMAKE_CURRENT_LIST_LINE}\nPROJECT_NAME---->${PROJECT_NAME}\n")

message(STATUS "HOME dir--->${HOME}\n")


message(STATUS "CMAKE_MAJOR_VERSION-->${CMAKE_MAJOR_VERSION}\nCMAKE_MINOR_VERSION--->${CMAKE_MINOR_VERSION}\nCMAKE_PATCH_VERSION--->${CMAKE_PATCH_VERSION}\nCMAKE_SYATEM---->${CMAKE_SYATEM}\nCMAKE_SYSTEM_NAME---->${CMAKE_SYSTEM_NAME}\nCMAKE_SYSTEM_VERSION---->${CMAKE_SYSTEM_VERSION}\nCMAKE_SYSTEM_PROCESSOR---->${CMAKE_SYSTEM_PROCESSOR}\n")

message(STATUS "CMAKE_C_COMPILER---->${CMAKE_C_COMPILER}")
message(STATUS "CMAKE_CXX_COMPILER---->${CMAKE_CXX_COMPILER}")

set(CMAKE_C_COMPILER "gcc")
set(CMAKE_CXX_COMPILER "g++")

message(STATUS "CMAKE_C_COMPILER---->${CMAKE_C_COMPILER}")
message(STATUS "CMAKE_CXX_COMPILER---->${CMAKE_CXX_COMPILER}")

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_EXAMPLE_C_FLAG1 -D_EXAMPLE_C_FLAG2 -Wall")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -frtti -fexceptions -D__STDC_FORMAT_MACROS -Wall")

message(STATUS "CMAKE_C_FLAGS--->${CMAKE_C_FLAGS}")

message(STATUS "CMAKE_CXX_FLAGS--->${CMAKE_CXX_FLAGS}")

# add compile attrs to c/c++
add_definitions(-DENABLE_DEBUG)

#define target dependencies other targets
#add_dependencies()

# contoller whether define Makefile build test target
#add_test()
#enable_testing()

#execute command, may output result by OUTPUT_VARIABLE and RESULT_VALUE
exec_program(ls ARGS "*.c" OUTPUT_VARIABLE MY_LS_OUTPUT RESULT_VALUE MY_LS_VALUE)

#if(not $MY_LS_VALUE)
message(STATUS "ls result:"${MY_LS_OUTPUT})
#endif(not $MY_LS_VALUE)

       #file operate
       #FILE(WRITE filename "message to write"... )
       #FILE(APPEND filename "message to write"... )
       #FILE(READ filename variable)
       #FILE(GLOB variable [RELATIVE path] [globbing expression_r_rs]...)
       #FILE(GLOB_RECURSE variable [RELATIVE path] [globbing expression_r_rs]...)
       #FILE(REMOVE [directory]...)
       #FILE(REMOVE_RECURSE [directory]...)
       #FILE(MAKE_DIRECTORY [directory]...)
       #FILE(RELATIVE_PATH variable directory file)
       #FILE(TO_CMAKE_PATH path result)
       #FILE(TO_NATIVE_PATH path result)

#use to load CMakeLists.txt file, also load predefine cmake module, if is module be to search by CMAKE_MODULE_PATH
#include(file1 [OPTIONAL])
#include(module [OPTIONAL])


#FIND_系列指令主要包含一下指令:
#FIND_FILE(<VAR> name1 path1 path2 ...)
#VAR 变量代表找到的文件全路径,包含文件名
#FIND_LIBRARY(<VAR> name1 path1 path2 ...)
#VAR 变量表示找到的库全路径,包含库文件名
#FIND_PATH(<VAR> name1 path1 path2 ...)
#VAR 变量代表包含这个文件的路径。
#FIND_PROGRAM(<VAR> name1 path1 path2 ...)
#VAR 变量代表包含这个程序的全路径。
#FIND_PACKAGE(<name> [major.minor] [QUIET] [NO_MODULE][[REQUIRED|COMPONENTS] [componets...]])
#用来调用预定义在 CMAKE_MODULE_PATH 下的 Find<name>.cmake 模块,你也可以自己定义 Find<name>模块,通过 SET(CMAKE_MODULE_PATH dir)将其放入工程的某个目录中供工程使用,我们在后面的章节会详细介绍 FIND_PACKAGE 的使用方法和 Find 模块的编写。

#FIND_LIBRARY 示例:
#FIND_LIBRARY(libX X11 /usr/lib)
#IF(NOT libX)
#MESSAGE(FATAL_ERROR “libX not found”)
#ENDIF(NOT libX)


add_subdirectory(math)

#aux_source_directory(${CMAKE_SOURCE_DIR} SRC_LIST)

set(A_SRC a.c)

include_directories(${CMAKE_SOURCE_DIR})

add_executable(a ${A_SRC})

target_link_libraries(a dl)

set(B_SRC b.cpp) 

add_executable(b ${B_SRC})



